<?php 
/**
 * 品牌模型表
 */
class BrandModel extends Model{
	
	public $table = 'brand';
	//自动验证
	public $validate = array(
		array('bname','nonull','品牌名称不能为空',2,3)

	);
	
	/**
	 * 添加品牌
	 */
	public function addBrand(){
		//执行自动验证
		if(!$this->create()) return false;
		//把上传类放到此处是为了先要执行自动验证，在往下做添加！！！！！！！！！！！
		//处理上传
		if($_FILES['logo']['error']!=4){
			$upload = new upload();
			//返回上传的信息
			$files = $upload->upload();
			//如果上传失败
			if(!$files){
				$this->error = $upload->error;
				return false;
			}
			//获取图片上传路径
			$logoPath = $files[0]['path'];
			//将路径压入到data的方法中，data会自动添加到表中!!!!!!!!!!
			$this->data['logo'] = $logoPath;
			
		}
		
		//执行添加
		$this->add();
		return true;
		
	}
	
	
	/**
	 * 修改品牌
	 */
	public function edit($bid){
		//执行自动验证
		if(!$this->create()) return false;
		//处理上传
		if($_FILES['logo']['error']!=4){
			$upload = new upload();
			$files = $upload->upload();
			if(!$files){
				$this->error = $upload->error;
				return false;
			}
			$logoPath = $files[0]['path'];
			$this->data['logo'] = $logoPath;
			
		}
		//执行更新
		$this->where("bid={$bid}")->update();
		return true;
		
	}
	
	
	
	
	
}













 ?>